package com.java.springcloud.controller;

import com.java.springcloud.util.ZkClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.CreateMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author dushougudu
 */
@RestController()
@RequestMapping("/zookeeper")
public class ZookeeperController {

    @Autowired
    ZkClient zkClient;

    @PostMapping("/createNode")
    public void createNode(String path, String data) {
        zkClient.createNode(CreateMode.EPHEMERAL, path, data);
    }

    @PostMapping("/getNodeData")
    public String getNodeData(String path) {
        return new String(zkClient.getNodeData(path));
    }

    @PostMapping("/getChildren")
    public List<String> getChildren(String path) {
        return zkClient.getChildren(path);
    }

}